<?php
require_once dirname(__FILE__).'/../bootstrap/doctrine.php';
$t = new lime_test(14);

//测试按照升序返回所有的类目对象集合函数
$t->comment('1.Test function getCategoriesQuery');
$t->comment('  1.1.getCategoriesQuery() is returns Doctrine_Collection?');
$t->isa_ok(Doctrine_Core::getTable('category')->getCategoriesQuery(), 'Doctrine_Query', 'yes!it is a Doctrine_Query');

//通过id号获取对象
$t->comment('2.check function getCategoryById()');
$t->isa_ok($c = Doctrine_Core::getTable('category')->getCategoryById(2),'category','get a catgory witch id is 2');
$t->is($c->getId(),2, 'id is 2');
$t->is($c->getName(),'通知公告', ' name is 通知公告');

//getAmount返回类目对象下面的动态信息数量
$t->comment('3.Test function getAmount');
$t->comment('  3.1.getAmount() is Belongs to category?');
$t->can_ok('category','getAmount', 'yes!it is belongs to Category');
$t->comment('  3.2.getAmount() returns integer?');
$t->isa_ok(Doctrine_Core::getTable('category')->getCategoriesQuery()->fetchOne()->getAmount(), 'integer', 'yes!it is a returns integer');
$t->comment('  3.3.getAmount() returns 5 when category_id is 2?');
$t->is($c->getAmount(),5,'yes!getAmount() returns 5 when category_id is 2.');

//根据分组号码获取相应类别的query
$t->comment('4.Test function getCategoriesQueryByGroups');
$t->comment('  4.1.it should returns doctrine_query');
$t->isa_ok(Doctrine_Core::getTable('category')->getCategoriesQueryByGroups(), 'Doctrine_Query', 'yes!it returns a Doctrine_Query');
$t->comment('  4.2.execute the query returns category witch id is 4 end name is 营养指南 when the parameter is 2');
$t->is(Doctrine_Core::getTable('category')->getCategoriesQueryByGroups('营养学堂')->fetchOne()->getId(),4,'yes!id is 4');
$t->is(Doctrine_Core::getTable('category')->getCategoriesQueryByGroups('营养学堂')->fetchOne()->getName(),'营养指南','yes!name is 营养指南');
$t->comment('  4.3.executes the function returns a category object?');
$t->isa_ok(Doctrine_Core::getTable('category')->getCategoriesQueryByGroups()->fetchOne(), 'category');

//getAmountByActiveStatus返回类目对象下面的相应状态动态信息数量
$t->comment('5.Test function getAmountByActiveStatus');
$t->comment('  5.1.getAmountByActiveStatus() is Belongs to category?');
$t->can_ok('category','getAmountByActiveStatus', 'yes!it is belongs to Category');
$t->comment('  5.2.getAmountByActiveStatus() returns integer?');
$t->isa_ok(Doctrine_Core::getTable('category')->getCategoriesQuery()->fetchOne()->getAmountByActiveStatus(TRUE), 'integer', 'yes!it is a returns integer');
$t->comment('  5.3.getAmountByActiveStatus() returns 5 when category_id is 2 and status is true?');
$t->is($c->getAmountByActiveStatus(TRUE),5,'yes!getAmount() returns 5 when category_id is 2 and status is true.');

?>
